package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.bean.DishFlavor;
import com.itheima.dao.DishFlavorDao;
import com.itheima.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DishFlavorServiceImpl implements DishFlavorService {

    @Autowired
    private DishFlavorDao dishFlavorDao;

    @Override
    public int add(DishFlavor dishFlavor) {
        return dishFlavorDao.insert(dishFlavor);
    }


    @Override
    public List<DishFlavor> findByDishId(long dishId) {
        //构建条件对象
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        //设置条件
        lqw.eq(DishFlavor::getDishId,dishId);

        // 执行查询
        return dishFlavorDao.selectList(lqw);
    }

    //删除
    @Override
    public int deleteByDishId(long dishId) {
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();

        //设置条件
        lqw.eq(DishFlavor::getId,dishId);

        //执行删除
        return dishFlavorDao.delete(lqw);
    }
}
